<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>refs</title>
  </head>

  <body>
    <!--  -->
    <!-- 准备好一个“容器” -->
    <div id="test"></div>
    <div id="test2"></div>

    <!-- 引入react核心库 -->
    <!-- <script type="text/javascript" src="js/react.development.js"></script> -->
    <script src="./js/v16.14.0/react.development_v16.14.0.js"></script>
    <!-- 引入react-dom，用于支持react操作DOM -->
    <!-- <script type="text/javascript" src="js/react-dom.development.js"></script> -->
    <script src="./js/v16.14.0/react-dom.development_v16.14.0.js"></script>
    <!-- 引入babel，用于将jsx转为js -->
    <script type="text/javascript" src="js/babel.min.js"></script>
    <!-- <script src="./change_weather.js"></script> -->
  </body>
  <script src="./js/prop-types.js"></script>
  <script type="text/babel">
    //   子组件
    class Son extends React.Component {
      constructor(props) {
        super(props);
        this.state = { count: 0 };
      }
      UNSAFE_componentWillReceiveProps(props) {
        //   componentWillReceiveProps(props){
        console.log("soncomponentWillReceiveProps", props);
      }
      render() {
        console.log("sonRender");
        return <div>son的名字是{this.props.username}</div>;
      }
    }
    class Dad extends React.Component {
      /* 初始化阶段：ReactDOM.render()触发=>初次渲染 */
      // componentWillMount(){
      UNSAFE_componentWillMount() {
        console.log("componentWillMount");
      }
      componentDidMount() {
        console.log("componentDidMount");
      }
      componentWillUnmount() {
        console.log("componentWillUnmount");
      }
      shouldComponentUpdate() {
        console.log("shouldComponentUpdate");
      }
      // componentWillUpdate(){
      UNSAFE_componentWillUpdate() {
        console.log("componentWillUpdate");
      }
      componentDidUpdate() {
        console.log("componentDidUpdate");
      }
      render() {
        console.log("render");
        return (
          <div>
            组件
            <Son username="carlos" />
          </div>
        );
      }
    }
    ReactDOM.render(<Dad />, document.getElementById("test"));
  </script>
</html>
